namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class GroupDataAccess
    {
        private WSGroupDataAccess.WSGroupDataAccess wDataAcess = new WSGroupDataAccess.WSGroupDataAccess();
        private SmartSoft.DAL.GroupDataAccess oDataAcess = new SmartSoft.DAL.GroupDataAccess();

        public GroupDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public DataSet GetDataSet()
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet();
            }
            else
            {
                return oDataAcess.GetDataSet();
            }
        }

        public DataTable GetTable(string ps_GrpCode)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetTable(ps_GrpCode);
            }
            else
            {
                table= oDataAcess.GetTable(ps_GrpCode);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetTable(string ps_GrpCode, bool pb_UserCheck, int pi_UserType)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetTable(ps_GrpCode, pb_UserCheck, pi_UserType);
            }
            else
            {
                return oDataAcess.GetTable(ps_GrpCode, pb_UserCheck, pi_UserType);
            }
        }

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }
    }
}